package com.yupi.yuoj.judge.codesandbox;

import com.yupi.yuoj.judge.codesandbox.model.ExecuteCodeRequest;
import com.yupi.yuoj.judge.codesandbox.model.ExecuteCodeResponse;
import lombok.extern.slf4j.Slf4j;

/**
 *
 * 代理类CodeSandboxProxy 继承 代码沙箱接口，重写executeCode方法。
 *
 * 代理类中接收CodeSandbox对象作为参数，从而创建代理对象CodeSandboxProxy，用于代理对象CodeSandbox
 */
@Slf4j
public class CodeSandboxProxy implements CodeSandbox{

    //构造函数：用于将原代码沙箱codeSandbox对象传入
    private final CodeSandbox codeSandbox;
    public CodeSandboxProxy(CodeSandbox codeSandbox) {
        this.codeSandbox = codeSandbox;
    }
    //重写CodeSandbox接口中的executeCode()方法，进行功能增强，返回
    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        log.info("代码沙箱请求信息：" + executeCodeRequest.toString());
        ExecuteCodeResponse executeCodeResponse = codeSandbox.executeCode(executeCodeRequest);
        log.info("代码沙箱响应信息：" + executeCodeResponse.toString());
        return executeCodeResponse;
    }
}
